package bookpad.model;

import java.io.Serializable;
import java.util.Map;

import javax.jdo.annotations.NotPersistent;
import javax.jdo.annotations.Persistent;

import org.slim3.datastore.Attribute;
import org.slim3.datastore.Model;

import com.google.appengine.api.datastore.Key;

@Model(schemaVersion = 1)
public class UserBook implements Serializable {

    private static final long serialVersionUID = 1L;

    @Attribute(primaryKey = true)
    private Key key;

    @Attribute(version = true)
    private Long version;

    @Persistent
    private String userId;

    @Persistent
    private String ASIN;

    @NotPersistent
    @Attribute(persistent = false)
    private Map<String, String> item;

    /**
     * 状態
     * 
     * @value to_read:読みたい,done:読んだ,in_reading:読み中
     */
    @Persistent
    private String status;

    /**
     * 感想
     * 
     * @value interesting:面白い,impress:感動した,boring:つまらない,difficult:難しい
     */
    @Persistent
    private String impression;

    /**
     * Returns the key.
     * 
     * @return the key
     */
    public Key getKey() {
        return key;
    }

    /**
     * Sets the key.
     * 
     * @param key
     *            the key
     */
    public void setKey(Key key) {
        this.key = key;
    }

    /**
     * Returns the version.
     * 
     * @return the version
     */
    public Long getVersion() {
        return version;
    }

    /**
     * Sets the version.
     * 
     * @param version
     *            the version
     */
    public void setVersion(Long version) {
        this.version = version;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((key == null) ? 0 : key.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        UserBook other = (UserBook) obj;
        if (key == null) {
            if (other.key != null) {
                return false;
            }
        } else if (!key.equals(other.key)) {
            return false;
        }
        return true;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUserId() {
        return userId;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getStatus() {
        return status;
    }

    public void setImpression(String impression) {
        this.impression = impression;
    }

    public String getImpression() {
        return impression;
    }

    public void setItem(Map<String, String> item) {
        this.item = item;
    }

    public Map<String, String> getItem() {
        return item;
    }

    public void setASIN(String aSIN) {
        ASIN = aSIN;
    }

    public String getASIN() {
        return ASIN;
    }
}
